/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package batailledesardennes.game.entity;

import batailledesardennes.game.GameConstants;
import batailledesardennes.game.GameEnv;
import batailledesardennes.game.entity.drawer.AnimatedEntityDrawer;
import batailledesardennes.game.entity.drawer.BaseEntityDrawer;
import batailledesardennes.game.entity.task.Task;
import batailledesardennes.game.entity.task.TaskManager;
import batailledesardennes.game.interfaces.Controllable;
import batailledesardennes.game.interfaces.Drawable;
import batailledesardennes.game.interfaces.Updatable;
import batailledesardennes.util.geomFloat.Point;
import batailledesardennes.util.geomFloat.Rectangle;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;

/**
 *
 * @author cghislai
 */
public class TestEntity extends BaseEntity implements Drawable, Updatable, Controllable {
   private TaskManager taskManager;
   private Rectangle rect;

   public TestEntity() {
      selectable = true;
      drawable = true;
      entityTypeId = GameConstants.ENTITY_TYPE_ID_TEST;
      pos = new Point(200, 200);
      rect = new Rectangle(-5, -5, 5, 5).translateTo(pos.getX(), pos.getY());
      
      taskManager = new TaskManager();
      
   }

   @Override
   public void register(GameEnv env) {
      this.env = env;
      env.getUpdatableManager().addUpdatable(this);
      env.getEntitiesManager().addEntity(this);
      
   }

   @Override
   public void unregister() {
      env.getUpdatableManager().removeUpdatable(this);
      env.getEntitiesManager().removeEntity(this);
   }

   @Override
   public void draw(Graphics g) {
      g.setColor(selected ? Color.red : Color.blue);
      g.fillRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());

//      g.setColor(Color.yellow);
//      Node node = new Node(pos);
//      List<Node> nodes = env.getMap().getAccessHandler().getNodeHandler().getConnectableNodes(node);
//      for (Node n : nodes) {
//         g.drawLine(pos.getX(), pos.getY(), n.getPoint().getX(), n.getPoint().getY());
//      }
   }

   @Override
   public short getDrawablePriority() {
      return GameConstants.DRAWABLE_PRIORITY_FRONT;
   }

   @Override
   public void update(int delta) {
      taskManager.update(delta);
//      rect.translateTo(pos);
   }

   @Override
   public void addTask(Task task, boolean queue) {
      if (!queue) {
         taskManager.clearTasks();
      }
      taskManager.addTask(task);
   }

    @Override
    public Rectangle getBounds() {
        return rect;
    }
}
